import http from '@/utils/request'
import type { AxiosPromise } from 'axios'

// 限时折扣活动接口定义
export interface DiscountActivityItem {
  id?: number
  discountName?: string // 活动名称
  startTime?: string // 开始时间
  endTime?: string // 结束时间
  state?: number // 活动状态 0-报名未开始 1-报名进行中 2-活动未开始 3-活动进行中 4-活动已结束
  createdAt?: string
  updatedAt?: string
}

export interface DiscountActivityListParams {
  discountName?: string // 活动名称
  page?: number
  pageSize?: number
  state?: number // 活动状态 0-报名未开始 1-报名进行中 2-活动未开始 3-活动进行中 4-活动已结束
}

export interface DiscountActivityListResponse {
  list: DiscountActivityItem[]
  total: number
}

// 查询限时折扣列表
export function getDiscountData(
  data: DiscountActivityListParams
): AxiosPromise<DiscountActivityListResponse> {
  return http.post({
    url: '/discount/getAll',
    data,
  })
}

// 查询限时折扣详情
export function getDiscountDetail(
  data: { id: number }
): AxiosPromise<DiscountActivityItem> {
  return http.post({
    url: '/discount/getById',
    data,
  })
}

// 添加限时折扣
export function addDiscountData(
  data: DiscountActivityItem
): AxiosPromise<DiscountActivityItem> {
  return http.post({
    url: '/discount/save',
    data,
  })
}

// 删除限时折扣
export function delDiscountData(
  data: { id: number }
): AxiosPromise<void> {
  return http.post({
    url: '/discount/delete',
    data,
  })
}

// 修改限时折扣
export function editDiscountData(
  data: DiscountActivityItem
): AxiosPromise<DiscountActivityItem> {
  return http.post({
    url: '/discount/update',
    data,
  })
}

// 停止限时折扣
export function stopDiscountData(
  data: { id: number }
): AxiosPromise<void> {
  return http.post({
    url: '/discount/stop',
    data,
  })
}

// 秒杀活动数据查询
export function getDiscountChart(
  data: { id: number }
): AxiosPromise<any> {
  return http.post({
    url: '/discount/getData',
    data,
  })
}

// 参与店铺查询
export function getDiscountShop(
  data: { id: number }
): AxiosPromise<any> {
  return http.post({
    url: '/discount/getShops',
    data,
  })
}

// 查看商品
export function getDiscountProduct(
  data: { id: number }
): AxiosPromise<any> {
  return http.post({
    url: '/discount/getProducts',
    data,
  })
}

// 导出商家明细
export function exportDiscountData(
  data: { discountId: number }
): AxiosPromise<Blob> {
  return http.post({
    url: '/discount/excel_shop_detail',
    data,
    responseType: 'blob',
  })
}